package com.qiqi.web;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qiqi.domain.PhoneNumberExample;
import com.qiqi.domain.PhoneNumberExample.Criteria;
import com.qiqi.service.phonenumber.PhoneNumberService;
/**
 * 首页controller
 * @author wangyoujin
 *
 */
@Controller
public class IndexController {
	@Autowired
	public PhoneNumberService phoneNumberService;
	@RequestMapping("/index")
	public String index(ModelMap model,String startwith,String numlike){
		model.put("startwith", startwith);
		model.put("numlike", numlike);
		return "index";
	}
	@RequestMapping("/findNum")
	@ResponseBody
	public Map<String, Object> findNum(int page,int pageSize,String startwith,String numlike){
		PhoneNumberExample query = new PhoneNumberExample();
		Criteria criteria = query.createCriteria();
		if(StringUtils.isNotBlank(startwith)){
			startwith+="%";
			criteria.andNumLike(startwith);
			
		}
		if(StringUtils.isNotBlank(numlike)){
			numlike="%"+numlike+"%";
			criteria.andNumLike(numlike);
		}
		criteria.andSelledEqualTo(0);
		query.setOrderByClause("createTime desc");
		Map<String, Object> res = phoneNumberService.findNumbersByPage(query, page, pageSize);
		return res;
	}
}
